<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        li{
            list-style: none;
        }
        body{
            background: url(../images/001.jpg);
        }
        ul{
            width: 680px;
            height: auto;
            margin: 50px auto;
        }
        ul li{
            float: left;
            width: 160px;
            height: 120px;
            padding: 5px;
        }
        ul li img{
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <input type="button" value="添加" id="btnadd">
    <ul>
        <li><img src="../images/001.jpg" alt=""></li>
        <li><img src="../images/002.jpg" alt=""></li>
        <li><img src="../images/003.jpg" alt=""></li>
        <li><img src="../images/004.jpg" alt=""></li>
    </ul>

    <script>
        //添加图片
        document.querySelector('#btnadd').onclick=function(){
            var html='<li><img src="../images/003.jpg" alt=""></li>'
            var ul=document.querySelector('ul');
            ul.innerHTML+=html;
        }


        var imgs=document.querySelectorAll('ul li img');
        for(var i=0;i<imgs.length;i++){   
            imgs[i].onclick=function(){
                // var filename=this.src;
                document.body.style.background='url('+this.src+')';
            }
        }

        // document.querySelector('ul').onclick=function(e){
        //     e=e||window.event;
        //     document.body.style.background='url('+e.target.src+')';
        // }
    </script>
</body>
</html>